<link href="/admins/css/yundan.css" rel="stylesheet" type="text/css" />
<style>
    #billboy{
        font-size: 14px;
        width: 80%;
    }
    #userdetail{
        line-height: 36px;
        padding-left: 20px;
        padding-bottom: 10px;
        font-size: 16px;
    }
    #userdetail input{
        width: 80%;
        height: 20px;
        font-size: 16px;
    }
    #bf{
        background-color: #eee;
        text-align: right;
        width: 200px;
        height: 50px;
    }
    #cf{
        width: 480px;
    }
</style>
<?php
if($this->ma == 1){
    echo '<script language="javascript" type="text/javascript">alert("信息发布成功！");location.href = "/admini/manageuser/mail/"; </script>';
}
?>
<div id="billboy">
    <div id='userdetail'>
        发布站内信
        <form action="" method="post" id="reMeAll">
        <table width="100%" border="1" cellpadding="0" cellspacing="0"> 
            <tr>
              <td id='bf'>发布类型：</td>
              <td id='cf' valign="middle" colspan="3">&nbsp;&nbsp;
                  <input type="radio" id="releaseType1" name="releaseType" class="releaseType" value="1" checked="checked" style="width: 20px;"/>&nbsp;&nbsp;个人
                  <input type="radio" id="releaseType2" name="releaseType" class="releaseType" value="2" style="width: 20px;margin-left: 20px;"/>&nbsp;&nbsp;群发
              </td>
            </tr>
            <tr class="userinfotr">
              <td id='bf'>所属用户：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="username" id="username" value="<?php echo $this->userresult?$this->userresult->nikename:"";?>"/></td>
              <td id='bf'>仓库号：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="storeno" id="storeno"  value="<?php echo $this->userresult?$this->userresult->storeno:"";?>"/></td>
            </tr>
            <tr>
              <td id='bf'>类型：</td>
              <td id='cf' colspan="3" valign="middle">&nbsp;&nbsp;<select id="type" name="type" style="width: 30%;height: 24px;font-size: 16px;">
                      <option value="1">系统消息</ooption>
                      <option value="2">交易消息</ooption>
                  </select></td>
            </tr>
            <tr>
              <td id='bf'>标题：</td>
              <td id='cf' colspan="3" valign="middle">&nbsp;&nbsp;<input type="text" name="title" id="title" /></td>
            </tr>
            <tr>
              <td id='bf'>附加内容：</td>
              <td id='cf' colspan="3" valign="middle">
                  <div style="margin-left:10px;">
                      <input type="button" id="addA" name="addA" value="添加链接" style="width: 80px;height: 36px;color: #F60;font-size: 16px;"/>
                  </div></td>
            </tr>
            <tr>
              <td id='bf' style="height:250px;">内容：</td>
              <td id='cf' colspan="3" valign="middle">&nbsp;&nbsp;<textarea name="message" id="message"  cols="99" rows="12" style="font-size:16px;resize:none;" ></textarea></td>
            </tr>
            <tr>
              <td id='bf' style="height:250px;">内容展示：</td>
              <td id='cf' colspan="3" valign="middle"><div class="showContent" style="margin-left:10px;overflow: auto;height: 250px;"></div></td>
            </tr>
            <tr>
                <td id='cf' colspan="4" align="right"><input type="hidden" name="userId" id="userId" value="<?php echo $this->userid;?>" /><input type="hidden" name="motion" id="motion" value="remessage" />
                    <input type="submit" id="submit" name="submit" value="添加消息" style="background-color: #1668A4;width: 80px;height: 36px;color: white;font-size: 16px;border-radius:8px;" />&nbsp;&nbsp;</td>
            </tr>
          </table>
          </form>
    </div>
</div>
<div class="tanchuang" style="display:none;width: 760px;">
    <div class="nui-msgbox">
        <div class="nui-msgbox-hd">附加内容</div>
        <a class="nui-msgbox-close" title="关闭"><b></b></a>
    </div>
    <div class="wt_top">
    	<div class="wt_nav">
            <ul>
            	<li class="wt_on"><a href="javascript:void(0)" id="addATitle">添加链接</a></li>
            </ul>
        </div>
    </div>
    <div class="wenti_box" id="addAConent" style="display: none;">
        <div class="wt_center table" style="width:700px;">
            <table>
                <tr>
                    <td style="width: 180px;text-align: right;padding-right: 20px;">链接地址：</td>
                    <td style="width: 420px;" class="w0"><input type="text" id="aUrl" name="aUrl" value="" style="width:380px;"/></td>
                </tr>
                <tr>
                    <td style="width: 180px;text-align: right;padding-right: 20px;">链接文字：</td>
                    <td style="width: 420px;" class="w0"><input type="text" id="aVal" name="aVal" value="" style="width:380px;"/></td>
                </tr>
                <tr>
                    <td style="width: 180px;text-align: right;padding-right: 20px;">打开方式：</td>
                    <td style="width: 420px;" class="w0">
                        <select id="aType" name="aType"><option value="1">新窗口打开</option><option value="2">原窗口打开</option></select></td>
                </tr>
                <tr class='content_bottom'>
                    <td colspan="4">
                        <div class="lctijiao" style="width: 200px;float: left;margin-left: 200px;">
                            <a class="anvbotton5" href="javascript:void(0)" id="subAdda"><span>确认</span></a>
                        </div>
                        <div class="" style="width: 50px;float: left;padding-top: 12px;">
                            <a href="javascript:void(0)" class="nui-btn-text retanchuang">取消</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="houtai_overlay" style="display:none;"></div>
<script type="text/javascript">
$(function(){
    $(".releaseType").click(function(){
        var type = $(this).val();
        if(type == 2){
            $(".userinfotr").hide();
            return ;
        }
        $(".userinfotr").show();
    });
    $("#addA").click(function(){
        $("#addATitle").closest("li").addClass("wt_on");
        $("#addATitle").closest("li").show();
        $("#addAConent").show();
        $(".houtai_overlay").show();
        $(".tanchuang").show();
    });
    $(".nui-msgbox-close").click(function(){
        $(".houtai_overlay").hide();
        $(".tanchuang").hide();
        $(".wenti_box").hide();
        $(".wt_nav ul li").removeClass("wt_on");
        $(".wt_nav ul li").hide();
    });
    $("#subAdda").click(function(){
        var aUrl = $("#aUrl").val();
        var aVal = $("#aVal").val();
        var aType = $("#aType").val();
        if(aUrl == ""){
            alert("地址链接不能为空！");
            return ;
        }
        if(aVal == ""){
            alert("链接内容不能为空！");
            return ;
        }
        var aHtml = "<a href='"+aUrl+"'";
        if(aType = 1){
            aHtml += " target='_blank' ";
        }
        aHtml += " class='indexa'>"+aVal+"</a>";
        var content = $("#message").val();
        content = content+aHtml;
        $("#message").val(content);
        $(".showContent").html(content.replace(/(\r)*\n/g,"<br/>").replace(/\s/g," "));
        $(".nui-msgbox-close").click();
    });
    $(".retanchuang").click(function(){
        $(".nui-msgbox-close").click();
    });
    $("#message").keyup(function(){
        var content = $("#message").val();
        $(".showContent").html(content.replace(/(\r)*\n/g,"<br/>").replace(/\s/g," "));
    });
    var isuser = true;
    $('#username').blur(function(){
        var username = $(this).val();
        if(username != ''){
            $.post('/admini/manageuser/bystoreno', {'username':username}, function(data){
                if(data.id != ""){
                    $('#storeno').attr('value',data.storeno);
                    $('#userId').attr('value',data.id);
                    isuser = true;
                }else{
                    isuser = false;
                    $('#storeno').attr('value','');
                    $('#userId').attr('value','');
                }
            }, 'json');
            return false;
        }else{
            $('#storeno').attr('value','');
            $('#userId').attr('value','');
            return false;
        }
    });
    $('#storeno').blur(function(){
        var storeno = $(this).val();
        if(storeno != ''){
            $.post('/admini/manageuser/byusername', {'storeno':storeno}, function(data){
                if(data.id != ""){
                    $('#username').attr('value',data.username);
                    $('#userId').attr('value',data.id);
                    isuser = true;
                }else{
                    alert("没有该用户，请重新输入所属用户！");
                    isuser = false;
                    $('#username').attr('value','');
                    $('#storeno').attr('value','');
                    $('#userId').attr('value','');
                }
            }, 'json');
        }else{
            $('#username').attr('value','');
            $('#userId').attr('value','');
        }
    });
    $('#submit').click(function(){
        var type = $("input[type='radio'][name='releaseType']:checked").val();
        var storeno = $('#storeno').val();
        var title = $('#title').val();
        var message = $('#message').val();
        if(type == 1){
            if(!isuser){
                alert("没有该用户，请重新输入所属用户！");
                return false;
            }
            if(storeno == ''){
                alert("没有该用户，请重新输入所属用户！");
                return false;
            }
        }
        if(title == ''){
            alert("信息标题不能为空！");
            return false;
        }
        if(message == ''){
            alert("信息内容不能为空！");
            return false;
        }
        return true;
    });
});
</script>